Migrate to uv & ruff, remove black and isort#290
Conversation
- Exclude tests/stubs/ from Ruff: generated .pyi fixtures use Python 3.12+ PEP 695 syntax which is invalid under target-version = "py310" - Run ruff format to fix parse.py after merging main Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace black and isort with ruff in test requirements.txt files - Fix format_stubs() path (was ./pybind11_stubgen, should be .) and remove --diff flag from ruff check so fixes are actually written - Update reference stubs with ruff's import ordering Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Drop uv run from test scripts; use tools directly from active env so both tox and CI work (uv run ignores VIRTUAL_ENV set by tox) - Pass dynamic --target-version to ruff so PEP 695 stubs (py3.12+) are parsed correctly during isort check - Activate .venv in CI before running stub/error check scripts - Update tox.ini: replace requirements-dev.txt deps with cmeel + cmeel-eigen, install local package instead of PyPI pybind11_stubgen - Update reference stubs to match ruff formatting (no blank lines after docstrings, union types without outer parens) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
uv venv does not include pip by default, so plain `pip install` falls
through to the system pip and installs demo outside the venv.
Using ${PYTHON_EXECUTABLE} -m pip ensures the venv's Python is used.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
uv venv creates environments without pip, so neither `pip install` nor `python -m pip` work. Use `uv pip install --python PYTHON_EXECUTABLE` which explicitly targets the correct interpreter in both CI and tox. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove blank lines after docstrings (ruff formatting) - Remove accept_annotated_callable from pybind11-v2.11 stubs (function not present in that version) - Update iterator/container type stubs for older pybind11 versions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| - name: Install uv | ||
| run: | | ||
| curl -LsSf https://astral.sh/uv/install.sh | sh | ||
| echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
There was a problem hiding this comment.
Any reason to not use a gh action?
- name: Install uv
uses: astral-sh/setup-uv@v7There was a problem hiding this comment.
Probably requirements.txt should not survive migration to uv
There was a problem hiding this comment.
Those are dependencies for test stubs, should we consider supplying a pyproject.toml there instead? Or an optional dependency group in the main one?
There was a problem hiding this comment.
I don't have a strong opinion on that one. Fine either way with me.
In general keeping number of formats/conventions/required tools makes maintenance simpler.
Sounds aligned with the goal of this PR: reducing friction in devs processes.
(Feel free to dismiss my sporadic comments. As I no longer use the project my perception of right/wrong might be quite a bit off.)
There was a problem hiding this comment.
I went with the [dev] section in the main pyproject.toml
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace curl uv installation with astral-sh/setup-uv@v7 in CI - Remove per-Python requirements.txt files in favor of pyproject.toml dev group - Add cmeel-eigen to dev dependency group - Move test deps (numpy, scipy, ruff, typing_extensions) into tox deps Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| - name: Setup annotations on Linux | ||
| if: runner.os == 'Linux' | ||
| run: python -m pip install pytest-github-actions-annotate-failures | ||
| run: uv pip install pytest-github-actions-annotate-failures |
There was a problem hiding this comment.
Codex spotted this:
This now installs pytest-github-actions-annotate-failures before uv sync. uv sync is exact by default, so it can remove packages that are not part of the synced dependency set, which makes that install step effectively redundant unless the package is moved after sync or added to the dev group.
In the current workflow that doesn’t change behavior, because these jobs never run pytest, so nothing consumes that plugin.
Summary
This PR migrates the project's tooling from pip/black/isort/flake8 to uv/ruff, and renames
master→mainin CI.CI changes
uv venv+uv pip installfor virtual environment setup and dependency installationruffinvocation; added a newcheckjob that runsruff format --diff,ruff check --select I,RUF022 --diff(isort), andruff checkmaininstead ofmasterScript changes (
tests/)install-demo-module.sh: replacedpip installwithuv pip install --python <exe>to install into the active venv without requiring pip to be present (uv venv doesn't include pip by default)check-demo-stubs-generation.sh: replacedblack+isortwithruff format+ruff check --select I,RUF022 --fix; added dynamic--target-versionto handle PEP 695 syntax in Python 3.12+ stubs; removed--diffflag from the fix step (diffs are shown later bygit diff --exit-code)check-demo-errors-generation.sh: removeduv runwrapper (not compatible with tox's virtual env activation)tox changes
requirements-dev.txtdependency (replaced with inlinedepsin tox.ini)PYTHON_TAG_FILEnow uses{envtmpdir}(per-env) instead of a shared path under{toxinidir}/tmp/cmeel-eigentodepsso it's available duringcommands_pre(cmake build)Reference stubs
tests/stubs/with ruff (import ordering and style differ slightly from isort+black)requirements.txtfiles: removedblackandisort, addedruff>=0.14.14pyproject.toml
exclude = ["tests/stubs"]to[tool.ruff]to prevent ruff from parsing PEP 695 stub syntax (e.g.def f[T](...)) with apy310target version🤖 Generated with Claude Code